package com.jlt.service.account;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.orm.Page;
import org.springside.modules.orm.PropertyFilter;

import com.jlt.dao.account.GroupDao;
import com.jlt.entity.account.Group;

/**
 * 组相关实体的管理类,.
 * 
 * @author zhoutao
 */
//Spring Bean的标识.
@Component
//默认将类中的所有函数纳入事务管理.
@Transactional
public class GroupManager {

	private static Logger logger = LoggerFactory.getLogger(GroupManager.class);

	private GroupDao groupDao;

	//-- Group Manager --//
	@Transactional(readOnly = true)
	public Group getGroup(Long id) {
		return groupDao.get(id);
	}
	
	/**
	 * 使用属性过滤条件查询组.
	 */
	@Transactional(readOnly = true)
	public Page<Group> searchGroup(final Page<Group> page, final List<PropertyFilter> filters) {
		return groupDao.findPage(page, filters);
	}

	@Transactional(readOnly = true)
	public List<Group> getAllGroup() {
		return groupDao.getAll("id", true);
	}

	public void saveGroup(Group entity) {
		groupDao.save(entity);
		logger.info("save group success");
	}

	public void deleteGroup(Long id) {
		groupDao.delete(id);
	}
	
	@Autowired
	public void setGroup(GroupDao groupDao) {
		this.groupDao = groupDao;
	}
}
